package com.devunion.bogdan.view.project;

import com.devunion.bogdan.model.project.Project;

import javax.swing.*;
import java.awt.*;

import org.apache.log4j.Logger;

/**
 * @author Viktar Liaskovich
 */
public class ProjectTreeBrowser extends JPanel {
    private static Logger log = Logger.getLogger(ProjectTreeBrowser.class);

    private JTree projectTree;

    public ProjectTreeBrowser() {
        setLayout(new BorderLayout());
    }

    public void openProject(Project project) {
        projectTree = ProjectTreeBuilder.getInstance().buildProjectTree(project);

        add(new JScrollPane(projectTree));

        validate();

        log.debug("Project opened: " + project.getName());
    }

    private void clear() {
        removeAll();

        ProjectTreeBuilder.getInstance().destroyProjectTree(projectTree);

        validate();

        log.debug("Project removed.");
    }

    public JTree getProjectTree() {
        return projectTree;
    }
}
